<?php

if(! defined('OT_ROOT')) {
	exit('Access Denied');
}


class AppVpsApi{
	public static $appName = 'IDC云服务器模块';
	private static $isApp = 0;

	public static function Jud(){
		return true;
	}



	// 登录自助管理平台
	public static function PanelLogin($dataID, $userID, $webPathPart=''){
		global $DB;
		
		if ($userID > 0){ $whereStr=' and VAU_userID='. $userID; }else{ $whereStr=''; }
		$showexe=$DB->query('select VAU_apiID,VAU_proDataID,VAU_state,VAU_serverCode,VAU_serverPwd,VAU_workId,VAU_workSign,VAU_vpsCpUrl,VAU_vpsName,VAU_vpsPwd,VAU_endTime from '. OT_dbPref .'vpsApiUsers where VAU_ID='. $dataID . $whereStr);
		if (! $row = $showexe->fetch()){ JS::AlertCloseEnd('指定ID或用户ID错误'); }
		if ($userID >= 0){
			if ($row['VAU_state'] < 10){ JS::AlertCloseEnd('云服务器状态不是正常状态['. $row['VAU_state'] .']'); }
			if (strtotime($row['VAU_endTime']) < time()){ JS::AlertCloseEnd('该云服务器已到期（'. $row['VAU_endTime'] .'）,请先续费再操作。'); }
		}

		if ($row['VAU_apiID'] == 1 || $row['VAU_apiID'] == 6){
			$VAD_typeID = intval($DB->GetOne('select VAD_typeID from '. OT_dbPref .'vpsApiData where VAD_ID='. $row['VAU_proDataID']));
			$VT_companyID = intval($DB->GetOne('select VT_companyID from '. OT_dbPref .'vpsType where VT_ID='. $VAD_typeID));
			$VC_apiManageUrl = $DB->GetOne('select VC_apiManageUrl from '. OT_dbPref .'vpsCompany where VC_ID='. $VT_companyID);

			if ($row['VAU_apiID'] == 6){
				// 网钛IDC
				IdcArea::PanelLoginIdccms($webPathPart, $VC_apiManageUrl, $row['VAU_vpsName'], Encrypt::SyEnDe('de',$row['VAU_vpsPwd']));
			}else{
				// 星外
				IdcArea::PanelLoginXingwai($webPathPart, $VC_apiManageUrl, $row['VAU_vpsName'], $row['VAU_vpsPwd']);	// VAU_vpsPwd假象所以无需解密
			}

		}elseif ($row['VAU_apiID'] == 2){
			IdcArea::PanelLoginJingan('vpsApi', $dataID, $row);
		
		}else{
			die('接口ID不对');
		}

		unset($row,$showexe);
	}
}
?>